#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>

int main(int argc, char *argv[])
{
    struct hostent *host;
    struct sockaddr_in addr;

    memset(&addr, 0, sizeof(addr));
    addr.sin_addr.s_addr = inet_addr(argv[1]);
    host = gethostbyaddr((char *)&addr.sin_addr, 4, AF_INET);

    printf("官方域名：%s \n", host->h_name);
    for(int i = 0;host->h_aliases[i];i++) {
        printf("别名 %d : %s\n", i + 1, host->h_aliases[i]);
    }
    printf("地址类型: %s\n",
           (host->h_addrtype == AF_INET) ? "AF_INET" : "AF_INET6");
    printf("地址长度：%d\n", host->h_length);
    for(int i = 0;host->h_addr_list[i];i++) {
        printf("IP地址 %d: %s \n", i + 1,
               inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
    }
    return 0;
}